#include "stdafx.h"
#include "ObjectModel.h"
#include "NFG.h"
#include "Constant.h"

cObjectModel::cObjectModel()
{
	m_uiVertexID = -1;
	m_uiIndiceID = -1;
	m_uiNumVertex = 0;
	m_uiNumIndice = 0;
	m_aVertexData = NULL;
	m_aIndiceData = NULL;
}

void cObjectModel::Init(char *fileModel)
{
	//Load data from source file model
	LoadNFG(fileModel, m_uiNumVertex, m_uiNumIndice, m_aVertexData, m_aIndiceData);

	//Binding vertex data
	glGenBuffers(1, &m_uiVertexID);
	glBindBuffer(GL_ARRAY_BUFFER, m_uiVertexID);
	glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * m_uiNumVertex, m_aVertexData, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	//Binding indice data
	glGenBuffers(1, &m_uiIndiceID);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_uiIndiceID);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * m_uiNumIndice, m_aIndiceData, GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

GLuint cObjectModel::GetVertexID()
{
	return m_uiVertexID;
}

GLuint cObjectModel::GetIndiceID()
{
	return m_uiIndiceID;
}

GLuint cObjectModel::GetVertexNumber()
{
	return m_uiNumVertex;
}

GLuint cObjectModel::GetIndiceNumber()
{
	return m_uiNumIndice;
}

cObjectModel::~cObjectModel()
{
	SAFE_DEL_ARRAY(m_aVertexData);
	SAFE_DEL_ARRAY(m_aIndiceData);
}